﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Page/Site.Master" AutoEventWireup="true" CodeBehind="Customer.aspx.cs" Inherits="ERP.Page.Customer" %>
<%@ MasterType VirtualPath="~/Page/Site.Master" %>
<%@ Register Src="~/PageUC/CustomerUC.ascx" TagPrefix="uc1" TagName="CustomerUC" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>
        function setSelected(selectObj, valueToSet) {
            for (var i = 0; i < selectObj.options.length; i++) {
                if (selectObj.options[i].value == valueToSet) {
                    selectObj.options[i].selected = true;
                    return;
                }
            }
        }
        function DetailRows(x) {
            //gets table
            var getTable = document.getElementById('MyTable');
            //gets cells of current row  
            var getCells = getTable.rows.item(x.rowIndex).cells;

            document.getElementById('<%=CustomerUC.lbID.ClientID %>').value = getCells.item(0).innerHTML;
            document.getElementById('<%=CustomerUC.txtMaKhachHang.ClientID %>').disabled = true;
            document.getElementById('<%=CustomerUC.txtMaKhachHang.ClientID %>').value = getCells.item(2).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drLoaiKhachHang.ClientID %>'), getCells.item(3).innerHTML);
            document.getElementById('<%=CustomerUC.txtTenVietTat.ClientID %>').value = getCells.item(4).innerHTML;
            document.getElementById('<%=CustomerUC.txtTenKhachHang.ClientID %>').value = getCells.item(5).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drLoaiHinhDoanhNghiep.ClientID %>'), getCells.item(6).innerHTML);
            document.getElementById('<%=CustomerUC.txtTenTiengAnh.ClientID %>').value = getCells.item(7).innerHTML;
            document.getElementById('<%=CustomerUC.txtHanMucNo.ClientID %>').value = getCells.item(8).innerHTML;
            document.getElementById('<%=CustomerUC.txtTenGiaoDich.ClientID %>').value = getCells.item(9).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiaChiGiaoDich.ClientID %>').value = getCells.item(10).innerHTML;
            document.getElementById('<%=CustomerUC.txtHanThanhToan.ClientID %>').value = getCells.item(11).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drTinh.ClientID %>'), getCells.item(12).innerHTML);
            setSelected(document.getElementById('<%=CustomerUC.drQuanHuyen.ClientID %>'), getCells.item(13).innerHTML);
            document.getElementById('<%=CustomerUC.txtNgayThanhLap.ClientID %>').value = getCells.item(14).innerHTML;
            document.getElementById('<%=CustomerUC.txtDienThoai1.ClientID %>').value = getCells.item(15).innerHTML;
            document.getElementById('<%=CustomerUC.txtDienThoai2.ClientID %>').value = getCells.item(16).innerHTML;
            document.getElementById('<%=CustomerUC.txtFax.ClientID %>').value = getCells.item(17).innerHTML;
            document.getElementById('<%=CustomerUC.txtWebsite.ClientID %>').value = getCells.item(18).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNganhNghe.ClientID %>'), getCells.item(19).innerHTML);
            document.getElementById('<%=CustomerUC.txtSoTaiKhoan.ClientID %>').value = getCells.item(20).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNguoiLienHe.ClientID %>'), getCells.item(21).innerHTML);
            document.getElementById('<%=CustomerUC.txtChucVu.ClientID %>').value = getCells.item(22).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNganHang.ClientID %>'), getCells.item(23).innerHTML);
            document.getElementById('<%=CustomerUC.txtDienThoai.ClientID %>').value = getCells.item(24).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiDong.ClientID %>').value = getCells.item(25).innerHTML;
            document.getElementById('<%=CustomerUC.txtEmail.ClientID %>').value = getCells.item(26).innerHTML;

            document.getElementById('<%=CustomerUC.txtTenDayDu.ClientID %>').value = getCells.item(27).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiaChiHopDong.ClientID %>').value = getCells.item(28).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drTinhHopDong.ClientID %>'), getCells.item(29).innerHTML);
            setSelected(document.getElementById('<%=CustomerUC.drQuanHuyenHopDong.ClientID %>'), getCells.item(30).innerHTML);
            document.getElementById('<%=CustomerUC.txtMaSoThue.ClientID %>').value = getCells.item(31).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNguoiKyHopDong.ClientID %>'), getCells.item(32).innerHTML);
            document.getElementById('<%=CustomerUC.txtChucVuHopDong.ClientID %>').value = getCells.item(33).innerHTML;
            document.getElementById('<%=CustomerUC.txtDienThoaiHopDong.ClientID %>').value = getCells.item(34).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiDongHopDong.ClientID %>').value = getCells.item(35).innerHTML;
            document.getElementById('<%=CustomerUC.txtEmailHopDong.ClientID %>').value = getCells.item(36).innerHTML;

            document.getElementById('<%=CustomerUC.txtDiaChiGiaoNhan.ClientID %>').value = getCells.item(37).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNguoiNhan.ClientID %>'), getCells.item(38).innerHTML);
            document.getElementById('<%=CustomerUC.txtChucVuNguoiNhan.ClientID %>').value = getCells.item(39).innerHTML;
            document.getElementById('<%=CustomerUC.txtDienThoaiNguoinhan.ClientID %>').value = getCells.item(40).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiDongNguoiNhan.ClientID %>').value = getCells.item(41).innerHTML;
            document.getElementById('<%=CustomerUC.txtEmailNguoiNhan.ClientID %>').value = getCells.item(42).innerHTML;

            document.getElementById('<%=CustomerUC.txtDiaChiThanhToan.ClientID %>').value = getCells.item(43).innerHTML;
            setSelected(document.getElementById('<%=CustomerUC.drNguoiThanhToan.ClientID %>'), getCells.item(44).innerHTML);
            document.getElementById('<%=CustomerUC.txtChucVuThanhToan.ClientID %>').value = getCells.item(45).innerHTML;
            document.getElementById('<%=CustomerUC.txtDienThoaiThanhToan.ClientID %>').value = getCells.item(46).innerHTML;
            document.getElementById('<%=CustomerUC.txtDiDongThanhToan.ClientID %>').value = getCells.item(47).innerHTML;
            document.getElementById('<%=CustomerUC.txtEmailThanhToan.ClientID %>').value = getCells.item(48).innerHTML;

            $("#khachhang").dialog("open");
        }
    </script>
    <script>
        function pageLoad() {
            //-------------------Tooltip-------------------
            Tooltip('.btn-add');
            Tooltip('.btn-delete');
            Tooltip('.btn-excel');
            Tooltip('.btn-search');
            Tooltip('.btn-reload');
            Tooltip('.btn-save');

            //--------------------Popup--------------------
            PopupUpdate('#khachhang');

            //--------------------DatePicker--------------------
            DatePicker('.textbox_child_text_ngay');
            MarkInputDay('.textbox_child_text_ngay');

            //------------------TabletSort-----------------
            TableSort('#MyTable');
            TableSort('#MyTableContact');
            //***********************************************
            $('#<%=CustomerUC.txtHanMucNo.ClientID %>').spinner();
            $('#<%=CustomerUC.txtHanThanhToan.ClientID %>').spinner();
            //---------------------------------------------
            $(".Check1 a").click(function () {
                $(".ChildCheck1").toggle();
            });
            $(".Check2").click(function () {
                $(".ChildCheck2").toggle();
            });
            $(".Check3").click(function () {
                $(".ChildCheck3").toggle();
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel ID="upDateAll" runat="server">
        <ContentTemplate>
            <!---------------Toolbar---------------->
            <div class="toolbar-main">
                    <button id="btnAdd" class="btn btn-default btn-sm" title="Thêm mới" onclick="return Show('#khachhang');"><span class="glyphicon glyphicon-pencil"></span>Thêm mới</button>
                    <asp:LinkButton ID="btnDelete" CssClass="btn btn-default btn-sm" title="Xóa" runat="server" OnClientClick="return confirmCheckIn(this)" OnClick="btnDelete_Click"><span class="glyphicon glyphicon-trash"></span> Xoá</asp:LinkButton>
                    <asp:LinkButton ID="btnExcel" CssClass="btn btn-default btn-sm" title="Xuất file Excel" runat="server"><span class="glyphicon glyphicon-print"></span> Xuất file Excel</asp:LinkButton>
            </div>
            <!---------------Toolbar---------------->
            <%=StrAlert %>
            <!----------------Loading---------------->
            <asp:UpdateProgress ID="upDateProcess" runat="server" AssociatedUpdatePanelID="upDateAll">
                <ProgressTemplate>
                    <span style="text-align: center" class="label label-warning">Đang tải...</span>
                </ProgressTemplate>
            </asp:UpdateProgress>
            <!--------------Kêt-thúc----------------->
            <!-------------Hiễn-Dữ-Liệu-------------->
            <div class="table-responsive">
                <asp:ListView ID="ListViewAll" runat="server" DataKeyNames="Customer_ID">
                    <LayoutTemplate>
                        <table id="MyTable" class="tablesorter">
                            <thead>
                                <tr>
                                    <th style="text-align: center" data-sorter="false" data-filter="false">STT</th>
                                    <th style="text-align: center" data-sorter="false" data-filter="false">
                                        <input type="checkbox" onchange="checkAll()" id="chkAll" />
                                    </th>
                                    <th style="text-align: center" class="filter-select" data-placeholder="--Chọn mã khách hàng--">Mã khách hàng</th>
                                    <th style="text-align: center" class="filter-select" data-placeholder="--Chọn tên khách hàng--">Họ & Tên</th>
                                    <th style="text-align: center" data-sorter="false" data-filter="false">Địa chỉ</th>
                                    <th style="text-align: center">Điện thoại 1</th>
                                    <th style="text-align: center">Điện thoại 2</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr id="itemPlaceholder" runat="server">
                                </tr>
                            </tbody>
                        </table>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <tr runat="server" ondblclick="DetailRows(this)" class="warning">
                            <td style="text-align: center"><%# Eval("Customer_ID") %></td>
                            <td style="text-align: center">
                                <asp:CheckBox ClientIDMode="Static" ID="chkList" runat="server" />
                            </td>
                            <td><%# Eval("Customer_Alias") %></td>
                            <td style="display: none"><%# Eval("Customer_Type_ID") %></td>
                            <td style="display: none"><%# Eval("Customer_Shortcut") %></td>
                            <td><%# Eval("Customer_Name") %></td>
                            <td style="display: none"><%# Eval("Enterprise_ID") %></td>
                            <td style="display: none"><%# Eval("Customer_Name_EN") %></td>
                            <td style="display: none"><%# Eval("Customer_Debt_Limit") %></td>
                            <td style="display: none"><%# Eval("Customer_Name_Exchange") %></td>
                            <td><%# Eval("Customer_Address") %></td>
                            <td style="display: none"><%# Eval("Customer_Payment_Deadline") %></td>
                            <td style="display: none"><%# Eval("Province_ID") %></td>
                            <td style="display: none"><%# Eval("District_ID") %></td>
                            <td style="display: none"><%# Eval("Customer_Establish") %></td>
                            <td><%# Eval("Customer_Phone1") %></td>
                            <td><%# Eval("Customer_Phone2") %></td>
                            <td style="display: none"><%# Eval("Customer_Fax") %></td>
                            <td style="display: none"><%# Eval("Customer_Website") %></td>
                            <td style="display: none"><%# Eval("Sector_ID") %></td>
                            <td style="display: none"><%# Eval("Customer_Account_Number") %></td>
                            <td style="display: none"><%# Eval("Customer_Contact") %></td>
                            <td style="display: none"><%# Eval("Job_Name") %></td>
                            <td style="display: none"><%# Eval("Bank_ID") %></td>
                            <td style="display: none"><%# Eval("Contact_Phone") %></td>
                            <td style="display: none"><%# Eval("Contact_MobilePhone") %></td>
                            <td style="display: none"><%# Eval("Contact_Email") %></td>

                            <td style="display: none"><%# Eval("Customer_Contract_FullName") %></td>
                            <td style="display: none"><%# Eval("Customer_Contract_Address") %></td>
                            <td style="display: none"><%# Eval("Province_Contract_ID") %></td>
                            <td style="display: none"><%# Eval("Customer_Contract_District") %></td>
                            <td style="display: none"><%# Eval("Customer_Contract_Tax_Code") %></td>
                            <td style="display: none"><%# Eval("Customer_Contract_Contact") %></td>
                            <td style="display: none"><%# Eval("Contract_Contact_Job") %></td>
                            <td style="display: none"><%# Eval("Contract_Contact_Phone") %></td>
                            <td style="display: none"><%# Eval("Contract_Contact_MobilePhone") %></td>
                            <td style="display: none"><%# Eval("Contract_Contact_Email") %></td>

                            <td style="display: none"><%# Eval("Customer_Delivery_Address") %></td>
                            <td style="display: none"><%# Eval("Customer_Delivery_Contact") %></td>
                            <td style="display: none"><%# Eval("Delivery_Contact_Job") %></td>
                            <td style="display: none"><%# Eval("Delivery_Contact_Phone") %></td>
                            <td style="display: none"><%# Eval("Delivery_Contact_MobilePhone") %></td>
                            <td style="display: none"><%# Eval("Delivery_Contact_Email") %></td>

                            <td style="display: none"><%# Eval("Customer_Payment_Address") %></td>
                            <td style="display: none"><%# Eval("Customer_Payment_Contact") %></td>
                            <td style="display: none"><%# Eval("Payment_Contact_Job") %></td>
                            <td style="display: none"><%# Eval("Payment_Contact_Phone") %></td>
                            <td style="display: none"><%# Eval("Payment_Contact_MobilePhone") %></td>
                            <td style="display: none"><%# Eval("Payment_Contact_Email") %></td>

                            <td style="display: none"><%# Eval("Customer_Note") %></td>
                        </tr>
                    </ItemTemplate>
                    <EmptyDataTemplate>
                        <div class='alert alert-danger'>
                            <a href='#' class='close' data-dismiss='alert'>&times;</a>
                            Không tìm thấy mẫu tin nào !
                        </div>

                    </EmptyDataTemplate>
                </asp:ListView>
            </div>
            <div class="pager">
                    <div class="toolbar-main">
                    <asp:LinkButton ID="btnReload" CssClass="btn btn-default btn-xs glyphicon glyphicon glyphicon-retweet" title="Tải lại" runat="server" OnClick="btnReload_Click"></asp:LinkButton>
                    &nbsp;
                    <asp:TextBox ID="txtSearch" CssClass="textbox-search" runat="server" />
                    <asp:LinkButton ID="btnSearch" CssClass="btn btn-default btn-xs glyphicon glyphicon glyphicon-search" title="Tìm kiếm" runat="server" OnClick="btnSearch_Click"></asp:LinkButton>
                    &nbsp;            
                    <span>Trang</span>
                        <select class="gotoPage" title="Select page number"></select>
                        <img src="../Content/TableSort/addons/pager/icons/first.png" class="first" alt="First" />
                        <img src="../Content/TableSort/addons/pager/icons/prev.png" class="prev" alt="Prev" />
                        <span class="pagedisplay"></span>
                        <img src="../Content/TableSort/addons/pager/icons/next.png" class="next" alt="Next" />
                        <img src="../Content/TableSort/addons/pager/icons/last.png" class="last" alt="Last" />
                    </div>
                </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnReload" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <!-------------Edit-Dữ-Liệu-------------->
    <div id="khachhang" title="Cập nhật khách hàng">
        <uc1:CustomerUC runat="server" id="CustomerUC" />
    </div>
    <!--------------Kêt-thúc----------------->
</asp:Content>
